<template>
  <el-card>
    <el-form inline>
      <el-form-item label="一级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          placeholder="请选择一级分类"
          size="large"
          v-model="categoryData.c1Id"
          @change="c1Handler"
        >
          <el-option
            v-for="(c1, index) in categoryData.c1Arr"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          placeholder="请选择二级分类"
          size="large"
          v-model="categoryData.c2Id"
          @change="c2Handler"
        >
          <el-option
            v-for="(c2, index) in categoryData.c2Arr"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          placeholder="请选择三级分类"
          size="large"
          v-model="categoryData.c3Id"
          @change="c3Handler"
        >
          <el-option
            v-for="(c3, index) in categoryData.c3Arr"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
import { onMounted } from 'vue'
import categoryDataStore from '@/store/modules/category'
const categoryData = categoryDataStore()
// 组件挂载完毕
onMounted(() => {
  getC1()
})

const getC1 = () => {
  categoryData.getC1()
}

const c1Handler = () => {
  // 一级分类发生改变的时候；需要清理 C2id C3id C3Arr
  categoryData.c2Id = ''
  categoryData.c3Id = ''
  categoryData.c3Arr = []
  categoryData.getC2()
}
const c2Handler = () => {
  // 二级分类发生改变的时候；需要清理  C3id
  categoryData.c3Id = ''
  categoryData.getC3()
}
// 接收父组件传递过来的scene
defineProps(['scene'])
</script>

<style scoped></style>
